<!doctype html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../assert_selection.js"></script>
<script>
// This tests interaction with user-triggered SelectAll command and selection.
// When selection is hidden, user-triggered SelectAll should act as if there is
// no selection at all.

test(() => {
  assert_own_property(window, 'testRunner', 'This test requires testRunner');

  assert_selection(
    'foo<textarea>bar|</textarea><a href="http://www.example.com">baz</a>',
    (selection, testRunner) => {
      selection.document.querySelector('a').focus();
      testRunner.execCommand('selectAll');
    },
    '^foo<textarea>bar</textarea><a href="http://www.example.com">baz|</a>')
}, 'User-triggered SelectAll selects entire document when there is unfocused caret selection hidden in text control');

test(() => {
  assert_own_property(window, 'testRunner', 'This test requires testRunner');

  assert_selection(
    'foo<textarea>^ba|r</textarea><a href="http://www.example.com">baz</a>',
    (selection, testRunner) => {
      selection.document.querySelector('a').focus();
      testRunner.execCommand('selectAll');
    },
    '^foo<textarea>bar</textarea><a href="http://www.example.com">baz|</a>')
}, 'User-triggered SelectAll selects entire document when there is unfocused range selection hidden in text control');

test(() => {
  assert_own_property(window, 'testRunner', 'This test requires testRunner');

  assert_selection(
    'foo<div contenteditable>bar|</div><a href="http://www.example.com">baz</a>',
    (selection, testRunner) => {
      selection.document.querySelector('a').focus();
      testRunner.execCommand('selectAll');
    },
    '^foo<div contenteditable>bar</div><a href="http://www.example.com">baz|</a>')
}, 'User-triggered SelectAll selects entire document when there is unfocused caret selection hidden in contenteditable div');

test(() => {
  assert_own_property(window, 'testRunner', 'This test requires testRunner');

  assert_selection(
    'foo<div contenteditable>^ba|r</div><a href="http://www.example.com">baz</a>',
    (selection, testRunner) => {
      selection.document.querySelector('a').focus();
      testRunner.execCommand('selectAll');
    },
    'foo<div contenteditable>^bar|</div><a href="http://www.example.com">baz</a>')
}, 'User-triggered SelectAll extends existing selection when there is unfocused range selection shown in contenteditable div');
</script>
